Imports System.IO
Imports System.Reflection
Imports System.Collections.Generic
Imports System.Linq
Imports Microsoft.Xna.Framework
Imports Microsoft.Xna.Framework.Audio
Imports Microsoft.Xna.Framework.Content
Imports Microsoft.Xna.Framework.GamerServices
Imports Microsoft.Xna.Framework.Graphics
Imports Microsoft.Xna.Framework.Input
Imports Microsoft.Xna.Framework.Media
Imports Microsoft.Xna.Framework.Input.Touch

Class Block
	Inherits Tile
    Private Shared tileSequence As New List(Of Sequence)()


	'seed 8x8
	Public Shared seed_graystone As Integer(,) = New Integer(,) {{2, 5, 14, 17, 56, 32, _
		35, 50}, {0, 0, 0, 0, 0, 0, _
		0, 0}, {0, 0, 0, 0, 0, 0, _
		0, 0}}
	Public Shared seed_left_bottom As Integer(,) = New Integer(,) {{2, 11, 36, 45, 0, 0, _
		0, 0}, {34, 47, 0, 0, 0, 0, _
		0, 0}, {0, 0, 0, 0, 0, 0, _
		0, 0}}
	Public Shared seed_left_top As Integer(,) = New Integer(,) {{37, 0, 0, 0, 0, 0, _
		0, 0}, {9, 10, 0, 0, 0, 0, _
		0, 0}, {16, 0, 0, 0, 0, 0, _
		0, 0}}
	Public Shared seed_right_bottom As Integer(,) = New Integer(,) {{27, 33, 0, 0, 0, 0, _
		0, 0}, {2, 8, 25, 35, 0, 0, _
		0, 0}, {0, 0, 0, 0, 0, 0, _
		0, 0}}
	Public Shared seed_right_top As Integer(,) = New Integer(,) {{4, 10, 31, 37, 0, 0, _
		0, 0}, {6, 12, 23, 29, 39, 0, _
		0, 0}, {0, 0, 0, 0, 0, 0, _
		0, 0}}
	Public Shared seed_line_wall As Integer(,) = New Integer(,) {{0, 0, 0, 0, 0, 0, _
		0, 0, 0, 0, 0, 0, _
		0, 0, 0, 0, 0, 0, _
		0, 0, 0, 0, 0, 0, _
		0, 0, 0, 0, 0, 0, _
		0, 0, 0, 0, 0, 0, _
		0, 0, 0, 0, 0, 0, _
		0, 0, 0, 0, 0, 0, _
		0, 0, 0, 0, 0}, {0, 1, 1, 0, 0, 0, _
		1, 1, 0, 0, 1, 1, _
		1, 0, 0, 1, 1, 1, _
		0, 0, 1, 1, 1, 0, _
		0, 1, 1, 1, 0, 0, _
		1, 1, 1, 0, 0, 1, _
		1, 1, 0, 0, 1, 1, _
		0, 0, 0, 1, 1, 0, _
		0, 0, 1, 1, 0}, {1, 0, 0, 1, 0, 0, _
		1, 0, 1, 1, 0, 1, _
		1, 0, 1, 1, 0, 1, _
		1, 0, 1, 1, 0, 1, _
		0, 0, 1, 0, 0, 1, _
		0, 0, 1, 0, 0, 1, _
		0, 0, 1, 0, 1, 1, _
		0, 1, 1, 0, 1, 1, _
		0, 1, 1, 0, 1}}
	Public Shared seed_line_offset As Integer(,) = New Integer(,) {{0, 0, 0, 0, 0, 0, _
		0, 0, 0, 0, 0, 0, _
		0, 0, 0, 0, 0, 0, _
		0, 0}, {5, 4, 3, 3, 1, 5, _
		4, 2, 1, 1, 5, 3, _
		2, 1, 5, 4, 3, 2, _
		5, 4}, {5, 4, 3, 3, 1, 5, _
		4, 2, 1, 1, 5, 3, _
		2, 1, 5, 4, 3, 2, _
		5, 4}}


	Public ReadOnly Property State() As Enumeration.StateTile
		Get
			Return tileState.Value().state
		End Get
	End Property


	Public Sub New(room As RoomNew, Content As ContentManager, tileType As Enumeration.TileType, state As Enumeration.StateTile, NextTileType As Enumeration.TileType)
		Me.nextTileType = NextTileType
		collision = Enumeration.TileCollision.Platform
		MyBase.room = room
		Dim ax As New System.Xml.Serialization.XmlSerializer(tileSequence.[GetType]())
		Dim txtReader As Stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(PrinceOfPersiaGame.CONFIG_PATH_CONTENT & PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES & tileType.ToString().ToUpper() & "_sequence.xml")


        tileSequence = DirectCast(ax.Deserialize(txtReader), List(Of Sequence))

		For Each s As Sequence In tileSequence
			s.Initialize(Content)
		Next


		'Search in the sequence the right type
		Dim result As Sequence = tileSequence.Find(Function(s As Sequence) s.name = state.ToString().ToUpper())

		If result IsNot Nothing Then
			'AMF to be adjust....
			result.frames(0).SetTexture(Content.Load(Of Texture2D)(PrinceOfPersiaGame.CONFIG_TILES & result.frames(0).value))

			collision = result.collision
			Texture = result.frames(0).texture
		End If
		Type = tileType


		'change statetile element
		tileState.Value().state = state
		tileAnimation.PlayAnimation(tileSequence, tileState.Value())
	End Sub

	Public Sub Normal()
		tileState.Value().state = Enumeration.StateTile.normal
		tileAnimation.PlayAnimation(tileSequence, tileState.Value())
	End Sub



End Class
